package bupt.xixi.loadbalancer;

import bupt.xixi.enumeration.BalancerType;
import bupt.xixi.enumeration.RpcError;
import bupt.xixi.exception.RpcException;

public class LoaderBalancerFactory {
    public static LoaderBalancer getBalancer(Integer balancerType) {
        if (null == balancerType) return null;
        if (BalancerType.RANDOM_BALANCER.getCode() == balancerType) return new RandomBalancer();
        if (BalancerType.ROUND_ROBIN_BALANCER.getCode() == balancerType) return new RoundRobinBalancer();
        throw new RpcException(RpcError.UNKNOWN_LOADER_BALANCER_TYPE);
    }
}
